import java.util.function.Predicate;

/**
 * @author zhu
 * @date 2024-04-10
 */
public class MainTest {
    public static void main(String[] args) {
        String[] emailAddresses = {
                "abc@example.com",
                "john.doe@example.com",
                "invalid_email",
                "test@example",
                "test@example@com"
        };

        Predicate<String> isValidEmail = email -> {
            if (email == null || email.length() < 6) {
                return false;
            }

            int count = 0;
            for (char c : email.toCharArray()) {
                if (c == '@') {
                    count++;
                }
            }

            return count == 1 && email.indexOf('@') > 0 && email.indexOf('@') < email.length() - 1;
        };

        for (String email : emailAddresses) {
            System.out.println(email + " 是否合法邮箱地址: " + isValidEmail.test(email));
        }
    }
}
